package com.springboot.astra.result;

public class DataResult<T> {
    private static final int CODE_SUCCESS=200;
    private static final int CODE_FAIL = 400;

    private static final String MSG_SUCCESS="success";
    private static final String MSG_FAIL="failed";

    private int code;
    private T data;
    private String msg;

    public DataResult() {
    }

    public DataResult(int code) {
        this.code = code;
    }

    public DataResult(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public DataResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public DataResult(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }
    public static DataResult success(){
        return new DataResult(CODE_SUCCESS,MSG_SUCCESS);
    }
    public static DataResult success(Object data){
        return new DataResult(CODE_SUCCESS,data,MSG_SUCCESS);
    }
    public static DataResult success(int code,Object data,String msg){
        return new DataResult(code,data,msg);
    }
    public static DataResult fail(){
        return new DataResult(CODE_FAIL,MSG_FAIL);
    }
    public static DataResult failWithMsg(String msg){
        return new DataResult(CODE_FAIL,msg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
